<?php
include("Card.class.php");

class Deck extends Card {
	public $cards;
	public $result;
	
	function __construct(){
	
		$cardFaces = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A');
		$suit = array('C','Q','F','P'); // cuori quadri fuori picche
		
		// Creazione mazzo
		foreach ($suit as $s){
			foreach($cardFaces as $c){
				$this->cards[] = new Card($c,$s);
			} 
		}
		// Dopo l'uso delle variabili le elimino
		unset($this->suit,$this->cardFaces);
		
		return $this->cards;
	}
	
	function printDeck(){
		foreach($this->cards as $c){
			echo $c->printCard();
		} 
	}
	
	// Mischia il mazzo
	function shuffleDeck(){ 
		shuffle($this->cards); 
		foreach($this->cards as $c){
			echo $c->printCard();
		} 
		
		return $this->cards;
	}
	
	// Prende l'ultima carta del mazzo, come se peschi
	function deal($input = null){
		if($input != null){
			$card = array_pop($input);
		}else{
			$card = array_pop($this->cards);
		}
		
		return $card->printCard();
	}
}
?>